/*
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with the
 * License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
 * 
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 * 
 * The Original Code is SemanticTurkey.
 * 
 * The Initial Developer of the Original Code is University of Roma Tor Vergata.
 * Portions created by University of Roma Tor Vergata are Copyright (C) 2007.
 * All Rights Reserved.
 * 
 * SemanticTurkey was developed by the Artificial Intelligence Research Group
 * (art.uniroma2.it) at the University of Roma Tor Vergata (ART) Current
 * information about SemanticTurkey can be obtained at
 * http://semanticturkey.uniroma2.it
 * 
 */
/**
 * @author NScarpato*/
 if (typeof art_semanticturkey == 'undefined')
	var art_semanticturkey = {};

art_semanticturkey.onload = function() {
	document.getElementById("chooseDir").setAttribute("value",
			"Select Directory To Save Annotations:");
	document.getElementById("chooseDir").setAttribute("control", "dirBtn");
	document.getElementById("dirBtn").setAttribute("label", "Select Directory");
	document.getElementById("dirBtn").addEventListener("click",
			art_semanticturkey.saveFile, true);
	document.getElementById("exportAnnotations").setAttribute("label",
			"Export Annotations");
	document.getElementById("exportAnnotations").addEventListener("click",
			art_semanticturkey.exportAnnotation, true);

	document.getElementById("cancel").setAttribute("label", "Cancel");
	document.getElementById("cancel").setAttribute("flex", "1");
	document.getElementById("cancel").addEventListener("click",
			art_semanticturkey.exportClose, true);
};
art_semanticturkey.exportAnnotation = function() {
	var file = document.getElementById("destDir").value + "/"
			+ document.getElementById("fileName").value;
	try {
		var responseXML = art_semanticturkey.ST_RangeRequests.RangeAnnotation
				.exportAnnotation(file);
		art_semanticturkey.exportAnnotation_RESPONSE(responseXML);
	} catch (e) {
		alert(e.name + ": " + e.message);
	}
};
art_semanticturkey.exportClose = function() {
	window.close();
};
art_semanticturkey.exportAnnotation_RESPONSE = function(responseElement) {
	alert("annotation properly exported");
	art_semanticturkey.exportClose();
};
window.addEventListener("load", art_semanticturkey.onload, true);